﻿Imports System.Data.SqlClient

Partial Class upload_page
    Inherits System.Web.UI.Page

    Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
       
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Session("username") = "Guest" Then
            Response.Redirect("login.aspx")
        End If

        If Not IsPostBack Then
            Try
                Dim cn As New SqlConnection(ConfigurationSettings.AppSettings("conn"))
                Dim cmd As New SqlCommand("select username,password,firstname,lastname,emailid,question,answer from users where username='" + Session("username") + "'", cn)
                Dim dr As SqlDataReader
                cn.Open()
                dr = cmd.ExecuteReader
                If dr.HasRows Then
                    dr.Read()
                    TextBox1.Text = dr(0)
                    TextBox6.Text = dr(1)
                    TextBox2.Text = dr(2)
                    TextBox3.Text = dr(3)
                    TextBox4.Text = dr(4)
                    TextBox7.Text = dr(5)
                    TextBox8.Text = dr(6)
                End If
            Catch
            End Try
        End If


    End Sub

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        Try
            Dim cn As New SqlConnection(ConfigurationSettings.AppSettings("conn"))
            Dim cmd As SqlCommand
            If TextBox6.Text = "" Then
                cmd = New SqlCommand("update users set emailid='" + TextBox4.Text + "', question='" + TextBox7.Text + "',answer='" + TextBox8.Text + "' where username='" + Session("username") + "'", cn)
            Else
                cmd = New SqlCommand("update users set password='" + TextBox6.Text + "',emailid='" + TextBox4.Text + "', question='" + TextBox7.Text + "',answer='" + TextBox8.Text + "' where username='" + Session("username") + "'", cn)
            End If
            cn.Open()
            cmd.ExecuteNonQuery()
            Label1.Text = "Your Profile is Updated"
        Catch
        End Try

    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("default.aspx")
    End Sub

    Protected Sub TextBox4_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged

    End Sub

    Protected Sub TextBox7_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox7.TextChanged

    End Sub

    Protected Sub TextBox8_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox8.TextChanged

    End Sub
End Class
